package io.renren.api.controller;
import io.renren.api.entity.BtCustomerProBaseinfoEntity;
import io.renren.api.service.BtCategroyManageService;
import io.renren.api.service.BtCustomerBaseService;
import io.renren.api.service.BtCustomerProBaseinfoService;
import io.renren.api.service.BtNavBarService;

import io.renren.common.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Iterator;

import java.util.List;
import java.util.Map;

@Controller
public class SearchPageController {
    @Autowired
    private BtNavBarService btNavBarService;
    @Autowired
    private BtCategroyManageService btCategroyManageService;
    @Autowired
    private BtCustomerBaseService btCustomerBaseService;
    @Autowired
    private BtCustomerProBaseinfoService btCustomerProBaseinfoService;
    @RequestMapping("/link")
    public String firstPage(HttpServletRequest req,Map<String, Object> backdata) {
        Map<String, String[]> aaa= req.getParameterMap();
        Map<String, Object> params= new HashMap<>();
        Iterator<Map.Entry<String, String[]>> entries = aaa.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry<String, String[]> entry = entries.next();
            System.out.println("Key =:: " + entry.getKey() + ", Value =:: " + entry.getValue()[0]);
            params.put(entry.getKey(),entry.getValue()[0]);
        }
        params.put("limit","5");
        params.put("order","asc");
        //params.put("page","2");

        PageUtils searchPage =btCustomerProBaseinfoService.queryPage(params);

        for(BtCustomerProBaseinfoEntity tb:(List<BtCustomerProBaseinfoEntity>)searchPage.getList()){
            tb.setImgs(tb.getImgs().split(";")[0]);
            tb.setLink("/detail/"+tb.getId());
        }
        backdata.put("searchlist",searchPage);
        backdata.put("param",params);
        List<Map<String,Object>> catagroy=btCategroyManageService.getListAllCatagroy();
        backdata.put("catagroy",catagroy);

        return "shop/list";
    }
}
